/**
 * @file Build mini program base config
 * @author ican<1173944134@qq.com>
 */

'use strict';

const path = require('path');

const DEV_SERVER_PORT = 9090;

module.exports = {
  verbose: false,
  root: path.join(__dirname, '..'),
  output: {
    dir: 'dist',
    depDir: 'src/common'
  },
  component: {
    extname: 'vue',
    template: {
      // 标签转换配置项
      transformTags: {
        // div p 将转为 view 标签
        div: 'view',
        p: 'view',
        ul: 'view',
        ol: 'view',
        li: 'view',
        // a 将标签转为 navigator 标签，href 属性 转为 url 属性
        a: {
          tag: 'navigator',
          href: 'url'
        },
        // img 将转为 image 标签
        img: 'image'
      }
    }
  },
  framework: [
    'data',
    'ref',
    'redux',
    'watch',
    'broadcast',
    ['behavior', '{useNativeBehavior: false}']
  ],
  processors: {
    babel7: {
      extnames: ['js']
    },
    postcss: {
      extnames: ['styl', 'css', 'less'],
      options: {
        plugins: {
          px2rpx: {
            // 设计稿尺寸
            designWidth: 750
          }
        }
      }
    }
  },

  // 启用开发 Server
  server: {
    port: DEV_SERVER_PORT,
    type: 'connect',
    // 需要安装 mock 中间件 npm i autoresponse --save-dev
    middlewares: [
      // {
      //     name: 'autoresponse',
      //     options: {
      //         post: true,
      //         get: true
      //     }
      // }
    ]
  },

  prod: {
    rules: [
      {
        match: '*.js',
        processors: [
          ['replacement', {'process.env.NODE_ENV': '"production"'}]
        ]
      }
    ]
  },

  dev: {
    rules: [
      {
        match: /\.(png|jpe?g|gif)(\?.*)?$/,
        processors: {
          tinyimg: {
            replaceRaw: true
          }
        }
      },
      {
        match: '*.js',
        processors: [
          ['replacement', {
            // 'https://online.com': 'https://dev.com',
            'process.env.NODE_ENV': '"development"'
          }]
        ]
      }
    ]
  },
  test: {
    rules: [
      {
        match: '*.js',
        processors: [
          ['replacement', {
            // 'https://online.com': 'https://test.com',
            'process.env.NODE_ENV': '"development"'
          }]
        ]
      }
    ]
  }
};
